package com.itheima.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.tanhua.api.AnnouncementApi;
import com.itheima.tanhua.domain.Announcement;
import com.itheima.tanhua.domain.BasePojo;
import com.itheima.tanhua.dubbo.mappers.AnnouncementMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author Lff
 * @date 2022/3/31
 */
@DubboService
public class AnnouncementApiImpl implements AnnouncementApi {
    @Autowired
    private AnnouncementMapper mapper;

    @Override
    public Page<Announcement> findByPage(Integer page, Integer pagesize) {
        Page<Announcement> announcementsPage = new Page<>(page, pagesize);
        LambdaQueryWrapper<Announcement> qw = Wrappers.lambdaQuery(Announcement.class);
        qw.orderByDesc(Announcement::getUpdated, Announcement::getCreateDate);
        mapper.selectPage(announcementsPage, qw);
        return announcementsPage;
    }
}
